<?php
	defined('BY_JYA') or exit('error');
	list($goodsid,$num,$type,$remark)=$arguments;
	if($_SESSION['onemerchid']){
		$setting=plugin('jy_goodsfwmerch')->plugin_setting('secury'.$_SESSION['onemerchid']);
	}else{
		$setting=$this->plugin_setting('secury');
	}
	if(!$setting['batch']){
		$setting['batch']=10;
		exi('请先设置好-参数设置--批号位数！','error');
	}
	$goods=pdo_get('jy_goodsfw_goods',array('id'=>$goodsid));
	if(!$goods){
		exi('指定商品不存在！','error');
	}
	$goods_code=$goods['code'];
	$seckey=random(32);
	$batch_code=rand(pow(10,($setting['batch']-1)), pow(10,$setting['batch'])-1);
	$security_codes=$this->made_security_code($goods_code,$batch_code,$num,$seckey);
	$show_code=array_shift($security_codes);
	$string='';
	switch($type){
		case 1:
			$string=implode("\r\n",$security_codes);
			break;
		case 2:
			foreach($security_codes as $code){
				$string.=$this->format($code)."\r\n";
			}
			break;
		case 3:
			foreach($security_codes as $code){
				$string.=custom_url('jy_goodsfw/search/main/code='.$code,true)."\r\n";
			}
			break;
			
	}
	if(!$string){
		exi('生成失败！','error');
	}
	$filename = ROOT_AT.random(10).".zip";
	$zip = new ZipArchive();
	$zip->open($filename,ZipArchive::CREATE);
	$zip->addFromString('code.txt',$string);
	$zip->close();
	$zip=cfc('files')->source_save($filename,'zip','zip');
	//print_r($zip);exit();
	@unlink($filename);
	$data=array(
		'uniacid'=>$_SESSION['uniacid'],
		'goods_id'=>$goodsid,
		'goods_code'=>$goods_code,
		'seckey'=>$seckey,
		'code'=>$batch_code,
		'status'=>1,
		'type'=>$type,
		'remark'=>$remark,
		'num'=>$num,
		'createtime'=>TIMESTAMP,
		'code_file'=>$zip,
		'show_code'=>$show_code,
	);
	pdo_insert('jy_goodsfw_batch',$data);
	return $zip;
